<!--
  @author:  long
  @date:    2023/3/7
  @file:    客户详情
  @require:
-->
<template>
  <div v-loading="checkInfoLoading">
    <el-row :gutter="20" class="details product-details">
      <el-col
        :span="5"
        class="details-left min-h-screen"
        style="min-height: 800px"
      >
        <el-card style="min-height: 100%">
          <div class="details-left-top details-left-box">
            <div class="top">
              <div class="top-img">
                <svg-icon
                  :icon-class="'svg_customer1'"
                  class="block w-80px h-80px m-auto mb-15px"
                />
              </div>
              <label>
                {{ details.customerName }}
              </label>
              <div class="pr-2">
                <el-rate v-model="details.starRating" size="small" disabled />
              </div>
              <p>
                <dict-tag
                  :options="customer_class"
                  :value="details.customerType"
                />
              </p>
            </div>
            <!--产品分类-->
            <el-row :gutter="24" class="mt-10">
              <el-col
                :span="8"
                class="border-r-2 border-fuchsia-600 border-gray-100 border-r-solid"
              >
                <p class="text-gray-700 font-bold text-base">1/10</p>
                <p class="text-sm mt-10px">工单</p>
              </el-col>
              <el-col
                :span="8"
                class="border-r-2 border-fuchsia-600 border-gray-100 border-r-solid"
              >
                <p class="text-gray-700 font-bold text-base">1/10</p>
                <p class="text-sm mt-10px">任务</p>
              </el-col>
              <el-col :span="8">
                <p class="text-gray-700 font-bold text-base">1/10</p>
                <p class="text-sm mt-10px">订单</p>
              </el-col>
            </el-row>
          </div>

          <el-row
            :gutter="24"
            class="my-2 border-b-2 border-fuchsia-600 border-gray-100 border-b-solid"
          >
            <el-col :span="12" class="mb-2">
              <el-button type="primary" @click="clickFn('followUp')"
                >写新跟进
              </el-button>
            </el-col>
            <el-col :span="12" class="mb-2">
              <el-button type="primary" plain>转移客户</el-button>
            </el-col>
            <el-col :span="12" class="mb-2" v-if="details.status !== '8'">
              <el-button type="primary" plain @click="handleOpenDialog('pool')"
                >移入公海
              </el-button>
            </el-col>
            <el-col :span="12" class="mb-2">
              <div>
                <el-checkbox-button
                  indeterminate
                  v-model="starFocus"
                  :class="starFocus ? 'w-100%' : 'w-100% starFocus'"
                  @change="focusChange"
                >
                  <div class="flex items-center">
                    <span class="font-normal">{{
                      starFocus ? '取消关注' : '重点关注'
                    }}</span>
                  </div>
                </el-checkbox-button>
              </div>
            </el-col>
            <el-col :span="12" class="mb-2">
              <el-button @click="toBusiness" type="primary" plain
                >添加商机
              </el-button>
            </el-col>
            <!--            <el-col :span="12" class="mb-2">-->
            <!--              <el-button class="mr-3">添加协作</el-button>-->
            <!--            </el-col>-->
            <el-col :span="12" class="mb-2">
              <el-dropdown>
                <el-button type="primary" plain
                  >&nbsp;&nbsp;添&nbsp;&nbsp;&nbsp;加&nbsp;&nbsp;
                </el-button>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item @click="clickFn('contacts')"
                      >联系人
                    </el-dropdown-item>
                    <el-dropdown-item @click="clickFn('order')"
                      >订单
                    </el-dropdown-item>
                    <el-dropdown-item @click="clickFn('contract')"
                      >合同
                    </el-dropdown-item>
                    <el-dropdown-item @click="clickFn('task')"
                      >任务
                    </el-dropdown-item>
                    <el-dropdown-item @click="clickFn('word')"
                      >工单
                    </el-dropdown-item>
                    <el-dropdown-item @click="clickFn('followUp')"
                      >跟进
                    </el-dropdown-item>
                    <el-dropdown-item @click="clickFn('appendix')"
                      >附件
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </el-col>
            <el-col :span="12" class="mb-2">
              <el-button type="primary" plain @click="checkInfo"
                >校验信息
              </el-button>
            </el-col>
          </el-row>
          <el-row
            class="my-5 border-b-2 border-fuchsia-600 border-gray-100 border-b-solid"
          >
            <el-col :span="24" class="mb-4">
              <span class="font-semibold text-xl">首联系人信息</span>
            </el-col>
            <el-col :span="24" class="flex item-center mb-2">
              <el-icon color="#409EFF" class="mr-1 text-2xl">
                <UserFilled />
              </el-icon>
              <span class="text-lg">{{ details.contactName }}</span>
            </el-col>
            <el-col :span="24" class="flex item-center mb-2">
              <el-icon color="#67C23A" class="mr-1 text-2xl">
                <PhoneFilled />
              </el-icon>
              <span class="text-lg">{{ details.contactNumber }}</span>
            </el-col>
          </el-row>
          <div class="my-4">
            <div class="font-semibold text-xl mb-4">客户信息</div>
            <ul class="cnt qzbm">
              <li>
                <el-icon>
                  <Notebook />
                </el-icon>
                <label>归属公司</label>
                <p>
                  {{ details.orgName != null ? details.orgName : '--' }}
                </p>
              </li>
              <li>
                <el-icon>
                  <Notebook />
                </el-icon>
                <label>归属部门</label>
                <p>{{ details.deptName != null ? details.deptName : '--' }}</p>
              </li>
              <li>
                <el-icon>
                  <Notebook />
                </el-icon>
                <label>归属人</label>
                <p>{{ details.userName != null ? details.userName : '--' }}</p>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="19">
        <el-card class="details-right" style="min-height: 800px">
          <div class="px-5 py-1" style="min-height: 100%">
            <el-tabs
              v-model="tabVal"
              class="details-right-tabs"
              @tabChange="tabChange"
            >
              <el-tab-pane label="概况信息" name="details">
                <template v-if="tabVal == 'details'">
                  <overview :details="details" />
                </template>
              </el-tab-pane>
              <el-tab-pane label="资料详情" name="info">
                <template v-if="tabVal == 'info'">
                  <details-info :details="details" />
                </template>
              </el-tab-pane>
              <el-tab-pane label="联系人" name="contact">
                <template v-if="tabVal == 'contact'">
                  <customer-contact />
                </template>
              </el-tab-pane>
              <el-tab-pane
                label="代账情况"
                name="accounting"
                v-if="details.customerType == '4'"
              >
                <template v-if="tabVal == 'accounting'">
                  <accounting-situation @handleReplace="handleReplace" />
                </template>
              </el-tab-pane>
              <el-tab-pane label="下级客户" name="lower">
                <template v-if="tabVal == 'lower'">
                  <lower-level-customer />
                </template>
              </el-tab-pane>
              <el-tab-pane label="跟进记录" name="follow">
                <template v-if="tabVal == 'follow'">
                  <FollowUpList :tableParam="followUpListParams"></FollowUpList>
                </template>
              </el-tab-pane>
              <!-- <el-tab-pane label="订单记录" name="order">
                <template v-if="tabVal == 'order'">
                  <DetailsOrderList
                    :tableParam="orderTableParam"
                  ></DetailsOrderList>
                </template>
              </el-tab-pane> -->
              <el-tab-pane label="发票记录" name="invoice">
                <template v-if="tabVal == 'invoice'">
                  <InvoiceRecord :tableParam="fistParams"></InvoiceRecord>
                </template>
                <!-- 附件列表使用 -->
              </el-tab-pane>
              <el-tab-pane label="任务记录" name="taskList">
                <template v-if="tabVal == 'taskList'">
                  <task-details :task-param="taskListParam"></task-details>
                </template>
              </el-tab-pane>
              <el-tab-pane label="工单记录"></el-tab-pane>
              <el-tab-pane label="相关附件" name="appendix">
                <template v-if="tabVal == 'appendix'">
                  <AppendixList :tableParam="followUpListParams"></AppendixList>
                </template>
              </el-tab-pane>
              <el-tab-pane label="归属记录"></el-tab-pane>
              <el-tab-pane label="操作日志" name="operat">
                <template v-if="tabVal == 'operat'">
                  <OperationLog :tableParam="followUpListParams"></OperationLog>
                </template>
              </el-tab-pane>
            </el-tabs>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-dialog
      v-model="dialogObj.visible"
      destroy-on-close
      :close-on-click-modal="false"
      :width="dialogObj.width"
      :title="dialogObj.title"
    >
      <!--  转入公海 -->
      <div v-if="dialogObj.model == 'pool'">
        <div class="flex">
          <div class="w-20">备注信息：</div>
          <div>
            <el-input
              v-model="statusDescription"
              rows="5"
              class="mb-2"
              maxlength="100"
              placeholder="输入内容"
              show-word-limit
              type="textarea"
            />
            <div class="text-xs">
              *转移到公海后此客户数据将属于公共资源，原归属人员不能再维护跟进和更新此客户数据。
            </div>
          </div>
        </div>
      </div>
      <template #footer>
        <el-button @click="handleCloseDialog">取消</el-button>
        <el-button type="primary" @click="dialogSave">保存</el-button>
      </template>
    </el-dialog>
    <!-- 附件 -->
    <Appendix :dialogParam="appendixParam" @close="closeFn"></Appendix>
    <!-- 跟进 -->
    <FollowUp :dialogParam="followUpParam" @close="closeFn"></FollowUp>
    <!--   新建任务   -->
    <TaskFrom :dialogParam="taskParam" @closeDialog="closeTask"></TaskFrom>
    <!-- 校验信息 -->
    <el-dialog
      v-model="checkInfoDialog"
      destroy-on-close
      :close-on-click-modal="false"
      title="校验信息"
    >
      <el-form v-model="formData">
        <template v-for="item in formItems" :key="item.key">
          <el-form-item
            :label="item.label"
            :prop="item.key"
            v-if="formData[item.key.toLowerCase()]"
          >
            <el-input
              v-model="formData[item.key.toLowerCase()]"
              disabled
            ></el-input>
          </el-form-item>
        </template>
      </el-form>
      <template #footer>
        <el-button @click="cancelUpdate">关闭</el-button>
        <el-button type="primary" @click="updateToERP">更新到ERP</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="CustomerDetails">
import FollowUp from '@/businessComponents/FollowUp'
import Appendix from '@/businessComponents/Appendix'

import AppendixList from '@/businessComponents/AppendixList'
import OperationLog from '@/businessComponents/OperationLog'
import FollowUpList from '@/businessComponents/FollowUpList'
import FixedOperation from '@/components/FixedOperation'
import Overview from '@/views/customerManage/customerModules/customerDetails/modules/Overview.vue'
import DetailsInfo from '@/views/customerManage/customerModules/customerDetails/modules/DetailsInfo.vue'
import CustomerContact from '@/views/customerManage/customerModules/customerDetails/modules/CustomerContact.vue'
import CustomerAccessories from '@/views/customerManage/customerModules/customerDetails/modules/CustomerAccessories.vue'
import LowerLevelCustomer from '@/views/customerManage/customerModules/customerDetails/modules/LowerLevelCustomer.vue'
import InvoiceRecord from '@/businessComponents/InvoiceRecord'
import DetailsOrderList from '@/businessComponents/DetailsOrderList'
import TaskFrom from '@/views/rsgl/taskManage/modules/add.vue'
import {
  addFocus,
  getCustomerInfo,
  getFocusInfo,
  updateForOpenSea
} from '@/api/customerManage/customerList'
import { getCurrentInstance } from 'vue'
import { getTreeNodeByParam } from '@/utils/commo'
import useCommonStore from '@/store/modules/common'
import useUserStore from '@/store/modules/user'
import { getDept } from '@/api/system/dept'
import {
  getFocus,
  saveFocus,
  getTaxauthorityDynamic
} from '@/api/common/common'

import AccountingSituation from '@/views/customerManage/customerModules/customerDetails/modules/AccountingSituation.vue'
import {
  encryptCode,
  decryptCode,
  upadteTaxpayer
} from '@/api/customer/customer'
import axios from 'axios'
import TaskDetails from '@/views/salesManage/businessManage/businessDetails/modules/taskDetails.vue'
import { encode_max_count } from '@/hooks/dict/contract'

const router = useRouter()
const { proxy } = getCurrentInstance()
// 通用数据store
const commonStore = useCommonStore()
const userStore = useUserStore()
const starFocus = ref(false)
const statusDescription = ref('') //移入公海状态备注
const orderTableParam = ref({})
const data = reactive({
  rete: '',
  details: {},
  tabVal: 'details',
  dialogObj: {
    visible: false,
    title: '',
    width: '50%',
    model: '',
    type: {
      task: { title: '新建任务', width: '40%' },
      pool: { title: '转入公海', width: '40%' }
    }
  },
  focusInfo: {},
  appendixParam: {}, //附件记录
  followUpParam: {}, //跟进
  fistParams: {} //发票参数
})
const {
  rate,
  details,
  followUpParam,
  appendixParam,
  tabVal,
  dialogObj,
  focusInfo,
  fistParams
} = toRefs(data)
const followUpListParams = ref({})
const { customer_class } = proxy.useDict('customer_class')
const taskParam = ref({})
const taskListParam = ref({
  businessType: '3',
  businessId: router.currentRoute.value.query.customerId,
  businessName: ''
})

// 字典 具体查看根目录DICT.md文件
const { gykglx_type, zfjglx_type, zzsqjlx_type, kjzdzz_code } = proxy.useDict(
  'gykglx_type',
  'zfjglx_type',
  'zzsqjlx_type',
  'kjzdzz_code'
)

const closeTask = () => {
  taskParam.value.isVisible = false
}

// 刷新页面
const handleReplace = async id => {
  tabVal.value = 'details'
  await router.replace({
    path: '/customerManage/customerModules/customerDetails',
    query: { customerId: id }
  })
  init()
}

// 跳转到添加商机
const toBusiness = () => {
  //新建商机
  router.push({
    path: '/sales/businessManage/addBusiness',
    query: {
      flag: 'add',
      customerId: router.currentRoute.value.query.customerId,
      customerName: details.value.customerName,
      type: 'customer'
    }
  })
}

/**
 * 添加联系人
 */
function addContacts() {
  router.push({
    path: '/customerManage/contactsModules/contactsAdd',
    query: {
      flag: 'add',
      customerId: router.currentRoute.value.query.customerId
    }
  })
}

const clickFn = type => {
  console.info('type', type)
  switch (type) {
    case 'contacts':
      // 联系人
      addContacts()
      break

    case 'order':
      // 订单
      let obj = {
        customerId: router.currentRoute.value.query.customerId,
        customerName: details.value.customerName
      }
      router.push({
        path: '/sales/indent/salesOrderForm',
        query: { salesOrderData: JSON.stringify(obj) }
      })

      break
    case 'contract':
      // 合同

      break
    case 'task':
      // 任务
      //   taskParam.value.isVisible = true
      //   taskParam.value.businessType = '3'
      //   taskParam.value.businessId = router.currentRoute.value.query.customerId
      //   taskParam.value.businessName = details.value.customerName
      let object = {
        businessType: '3',
        businessId: router.currentRoute.value.query.customerId,
        businessName: details.value.customerName
      }
      router.push({
        path: '/rsgl/other/addTasking',
        query: { taskParam: JSON.stringify(object) }
      })

      break
    case 'word':
      // 工单

      break
    case 'followUp':
      // 跟进
      followUpParam.value.isVisible = true
      followUpParam.value.tableName = 'biz_customer'
      followUpParam.value.businessId =
        router.currentRoute.value.query.customerId
      followUpParam.value.customer = details.value.customerName
      followUpParam.value.linkId = details.value.coId ? details.value.coId : '' //'联系人id'
      followUpParam.value.linkName = details.value.contactName
        ? details.value.contactName
        : '' //'联系人名称'
      followUpParam.value.status = details.value.status //客户状态

      break
    case 'appendix':
      // 附件
      appendixParam.value.isVisible = true
      appendixParam.value.tableName = 'biz_customer'
      appendixParam.value.businessId =
        router.currentRoute.value.query.customerId
      break
  }
}
// 组件关闭隐藏
const closeFn = row => {
  switch (row) {
    case 'contractStatus':
      // 合同信息 操作完成
      init()
      break
    case 'order':
      // 订单

      break
    case 'contract':
      // 合同

      break
    case 'task':
      // 任务

      break
    case 'word':
      // 工单

      break
    case 'followUp':
      // 跟进
      followUpParam.value.isVisible = false
      init()
      break
    case 'appendix':
      // 附件
      appendixParam.value.isVisible = false
      init()
      break
  }
}

/**
 * 弹窗关闭
 */
function handleCloseDialog() {
  dialogObj.value.visible = false
}

/**
 * 弹窗开启操作
 * @param type 弹窗组件类型
 *
 */
function handleOpenDialog(type) {
  dialogObj.value.title = dialogObj.value.type[type].title
  dialogObj.value.width = dialogObj.value.type[type].width
  dialogObj.value.model = type
  dialogObj.value.visible = true
}

/**
 * 弹窗保存
 */
function dialogSave() {
  switch (dialogObj.value.model) {
    case 'pool': //公海
      console.info('公海保存')
      let params = [
        {
          statusDescription: statusDescription.value,
          id: router.currentRoute.value.query.customerId,
          status: '8',
          userId: '0',
          userName: '-'
        }
      ]
      // 移入公海
      updateForOpenSea(params).then(res => {
        proxy.$modal.msgSuccess(res.msg)
        dialogObj.value.visible = false
      })
      break
  }
}

/**
 * 获取客户详情
 */
const getCustomerInfoData = () => {
  let id = router.currentRoute.value.query.customerId
  getCustomerInfo(id).then(async res => {
    let obj = { ...res.data.co, ...res.data.vo }
    obj.coId = res.data.co ? res.data.co.id : ''
    obj.starRating = parseInt(obj.starRating)
    details.value = obj
    console.info('details.value', details.value)
    //设置跟进列表参数
    initFollowSession()
    //获取部门人员数据
    const deptUserData = await commonStore.getUseTreeData()
    getDept(obj.deptId).then(res => {
      details.value.deptName = res.data.deptName
    })
    getDept(obj.orgId).then(res => {
      details.value.orgName = res.data.deptName
    })
    //根据当前用户id获取uuid
    let userObj = getTreeNodeByParam(
      deptUserData,
      details.value.userId,
      'id',
      []
    )
    details.value.userName = userObj[0].label
    taskListParam.value.businessName = details.value.customerName
  })
}

/**
 * 切换
 */
function tabChange(val) {
  console.info(123)
  if (val == 'details') {
    getCustomerInfoData()
  } else if (val == 'order') {
    orderTableParam.value = {
      id: router.currentRoute.value.query.customerId,
      name: details.value.customerName,
      type: 'customer'
    }
  }
}

/**
 * 切换重点关注
 */
function focusChange() {
  let params = {
    businessId: router.currentRoute.value.query.customerId,
    tableName: 'biz_customer',
    userId: userStore.user.userId,
    focus: starFocus.value
  }
  saveFocus(params).then(res => {
    proxy.$modal.msgSuccess('操作成功')
  })
}

/**
 * 获取客户重点关注详情
 */
async function getFocusInfoData() {
  const focusRes = await getFocus({
    businessId: router.currentRoute.value.query.customerId,
    tableName: 'biz_customer'
  })
  starFocus.value = focusRes.data ? focusRes.data : false
}

const initFollowSession = () => {
  // 客户模块
  followUpListParams.value = {
    businessId: router.currentRoute.value.query.customerId,
    busineName: details.value.customerName,
    tableName: 'biz_customer'
  }
  console.info('followUpListParams.value', followUpListParams.value)
}

/**
 * 初始化
 */
async function init() {
  if (router.currentRoute.value.query.tabPane) {
    tabVal.value = router.currentRoute.value.query.tabPane
  }
  fistParams.value = {
    id: router.currentRoute.value.query.customerId,
    type: 'customer'
  }
  // 获取客户详情
  await getCustomerInfoData()
  // 获取关注重点详情
  await getFocusInfoData()
}

/**
 *  校验信息
 */

//  税号加密 =》 调接口 =》取返回值调接口解密 =》显示内容 =》是否更新到erp
const checkInfoDialog = ref(false)
const checkInfoLoading = ref(false)
const formItems = [
  {
    label: '社会信用代码',
    key: 'SHXYDM'
  },
  {
    label: '主管税务局代码',
    key: 'ZGSWJ_DM'
  },
  {
    label: '主管税务局',
    key: 'zgswj'
  },
  {
    label: '有效标志',
    key: 'nsrzt_dm' // 'YXBZ'
  },

  {
    label: '生产经营地址',
    key: 'SCJYDZ'
  },
  {
    label: '纳税人名称',
    key: 'NSRMC'
  },
  {
    label: '注册资本',
    key: 'zczb' // 'YXBZ'
  },
  {
    label: '注册地联系电话',
    key: 'ZCDLXDH'
  },
  {
    label: '法定代表人姓名',
    key: 'FDDBRXM'
  },
  {
    label: '法定代表人固定电话',
    key: 'FDDBRGDDH'
  },
  {
    label: '法定代表人移动电话',
    key: 'FDDBRYDDH'
  },
  {
    label: '财务负责人姓名',
    key: 'CWFZRXM'
  },
  {
    label: '财务负责人固定电话',
    key: 'CWFZRGDDH'
  },
  {
    label: '财务负责人移动电话',
    key: 'CWFZRYDDH'
  },
  /**
   * 新增
   *   企业注册时间
   *    行业类型
   *    从业人数
   *    主管税务所(科、分局)代码
   *    非居民企业标志
   *    文化事业建设费缴费信息登记标志
   *    国有控股类型代码
   *    会计制度(准则)代码
   *    增值税企业类型代码
   *    经营范围
   *    总分机构类型代码
   *    税务代理人名称
   */
  {
    label: '企业注册时间',
    key: 'djrq'
  },
  {
    label: '行业类型',
    key: 'hyDm'
  },
  {
    label: '从业人数',
    key: 'cyrs'
  },
  {
    label: '主管税务所(科、分局)代码',
    key: 'zgswskfjDm'
  },
  {
    label: '非居民企业标志',
    key: 'fjmqybz'
  },
  {
    label: '文化事业建设费缴费信息登记标志',
    key: 'whsyjsfjfxxdjbz'
  },
  {
    label: '国有控股类型代码',
    key: 'gykglxDm'
  },
  {
    label: '会计制度(准则)代码',
    key: 'kjzdzzDm'
  },
  {
    label: '增值税企业类型代码',
    key: 'zzsqylxDm'
  },
  {
    label: '经营范围',
    key: 'jyfw'
  },
  {
    label: '总分机构类型代码',
    key: 'zfjglxDm'
  },
  {
    label: '税务代理人名称',
    key: 'swdlrmc'
  }
]

const formData = ref({})
const submitFormData = ref({})
const taxId = ref()

async function checkInfo() {
  checkInfoLoading.value = true
  try {
    const encode = await encryptCode({
      nsrsbh: details.value.customerTaxcode,
      max: Number(ref(encode_max_count).value[0].value)
    })
    // 测试环境：http://222.76.49.184:8021/TamClientT/doService.do
    //正式环境：http://222.76.49.184:8021/TamClient/doService.do
    let tamClientUrl = import.meta.env.VITE_TamClient_URL
    axios
      .post(tamClientUrl, encode.msg, {
        headers: {
          'Content-Type': 'text/plain' // 设置Content-Type为纯文本
        }
      })
      .then(async res => {
        const decode = await decryptCode({ nsrsbh: res.data })
        if (decode.code === 200) {
          checkInfoDialog.value = true
          //submitFormData 提交用数据
          submitFormData.value = JSON.parse(JSON.stringify(decode.data))
          //   数据处理
          formData.value = Object.keys(decode.data).reduce((acc, cur) => {
            if (decode.data[cur] !== '') {
              if (cur.toLowerCase() == 'hydm') {
                //国有控股类型代码
                acc[cur.toLowerCase()] = decode.data.hyDmStr
              } else if (cur.toLowerCase() == 'gykglxdm') {
                //国有控股类型代码
                acc[cur.toLowerCase()] = gykglx_type.value.find(
                  item => item.value == decode.data[cur]
                ).label
              } else if (cur.toLowerCase() == 'zfjglxdm') {
                //总分机构类型代码
                acc[cur.toLowerCase()] = zfjglx_type.value.find(
                  item => item.value == decode.data[cur]
                ).label
              } else if (cur.toLowerCase() == 'zzsqylxdm') {
                //增值税企业类型代码
                acc[cur.toLowerCase()] = zzsqjlx_type.value.find(
                  item => item.value == decode.data[cur]
                ).label
              } else if (cur.toLowerCase() == 'kjzdzzdm') {
                //会计制度(准则)代码
                acc[cur.toLowerCase()] = kjzdzz_code.value.find(
                  item => item.value == decode.data[cur]
                ).label
              } else if (cur.toLowerCase() == 'fjmqybz') {
                //非居民企业标志
                acc[cur.toLowerCase()] = decode.data[cur] == 'Y' ? '是' : '否'
              } else if (cur.toLowerCase() == 'whsyjsfjfxxdjbz') {
                //文化事业建设费缴费信息登记标志
                acc[cur.toLowerCase()] = decode.data[cur] == 'Y' ? '是' : '否'
              } else {
                acc[cur.toLowerCase()] = decode.data[cur]
              }
            } else {
              acc[cur.toLowerCase()] = decode.data[cur]
            }

            return acc
          }, {})

          console.info('formData.value', formData.value)
        }
        const taxCode = await getTaxauthorityDynamic(
          formData.value.zgswj_dm.slice(0, 9)
        )
        if (taxCode.code === 200) {
          formData.value.zgswj = taxCode.data[0].label
          submitFormData.value.zgswj = taxCode.data[0].label
          taxId.value = taxCode.data[0].id
        }
      })
      .finally(() => {
        checkInfoLoading.value = false
      })
  } catch (error) {
    checkInfoLoading.value = false
    console.error(error, 'catch')
  }
}

// 取消弹窗
function cancelUpdate() {
  checkInfoDialog.value = false
}

// 更新到ERP
function updateToERP() {
  // formData.value.zgswj_dm = taxId.value
  let id = router.currentRoute.value.query.customerId
  submitFormData.value.entType = 1
  submitFormData.value.fddbrCode = 5
  submitFormData.value.cwfzrCode = 11
  submitFormData.value.entId = id
  submitFormData.value.contactType = details.value.customerType
  upadteTaxpayer(submitFormData.value).then(res => {
    if (res.code === 200) {
      proxy.$modal.msgSuccess('更新成功')
      cancelUpdate()
      init()
    }
  })
  cancelUpdate()
}

init()
</script>

<style scoped lang="scss">
@import '@/assets/styles/detailsStyle.scss';

:deep(.el-form-item__label) {
  width: 200px;
}

:deep(.el-form-item__content) {
  width: 70% !important;
  flex: none;
}
</style>
